package com.zmx.common.common.config.shardingsphere;

import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

/**
 * @Description: 自定义分表 根据用户后四位id取模 格式：tablename_用户后四位id取模
 * @ClassName: TableShardingAlgorithm
 * @Author zhaomxr
 * @Date 2021-12-08 16:19
 */
@Slf4j
public class TableBySupplierIdShardingAlgorithm extends TableByIdShardingAlgorithm implements PreciseShardingAlgorithm<Integer> {

    private final static int SHARDINGNUM = 4;

    @Override
    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Integer> preciseShardingValue) {
        return sharding(availableTargetNames, preciseShardingValue, SHARDINGNUM);
    }

}
